package com.ctvit.sjk.knowledge.app.pojo.vo;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.ctvit.sjk.knowledge.app.pojo.domain.TabAppApiKey;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.apache.commons.lang3.ObjectUtils;

import java.time.LocalDateTime;

/**
 * 应用API密钥查询VO
 *
 * @author heyingcheng
 * @date 2025/03/29
 */
@Getter
@Setter
@ToString
public class AppApiKeyGetVO {

    private String id;
    @JsonProperty("secret_key")
    private String secretKey;
    @JsonProperty("is_active")
    private Boolean isActive;
    @JsonProperty("allow_cross_domain")
    private Boolean allowCrossDomain;
    @JsonProperty("cross_domain_list")
    private JSONArray crossDomainList;
    private String user;
    private String application;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @JsonProperty("create_time")
    private LocalDateTime createTime;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @JsonProperty("update_time")
    private LocalDateTime updateTime;

    public AppApiKeyGetVO(TabAppApiKey entity) {
        this.id = entity.getApiKeyId();
        this.secretKey = entity.getSecretKey();
        this.isActive = entity.getActiveFlag();
        this.allowCrossDomain = entity.getAllowCrossDomain();
        this.crossDomainList = JSON.parseArray(ObjectUtils.defaultIfNull(entity.getCrossDomainList(), "[]"));
        this.user = entity.getCreateId();
        this.application = entity.getAppId();
        this.createTime = entity.getCreateTime();
        this.updateTime = entity.getUpdateTime();

    }

}
